package com.x.erp.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.x.erp.dao.CarPrintDao;
import com.x.erp.model.CarPrint;
import com.x.erp.rpc.CarPrintRpcService;
import com.x.framework.exception.BusinessException;
import com.x.framework.exception.ExceptionCode;
import com.x.framework.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by gdf on 2018/1/23.
 */
@Component
@Service(interfaceName = "com.x.erp.rpc.CarPrintRpcService", timeout = 60000)
public class CarPrintService extends BaseService implements CarPrintRpcService {

    @Autowired
    private CarPrintDao carPrintDao;

    /**
     * 查询打印次数列表
     * @param carPrint
     * @return
     */
    @Override
    public List<CarPrint> selectCarPrintList(CarPrint carPrint){
        try {
            return carPrintDao.selectRotationList(carPrint);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

    /**
     * 新增打印次数
     * @param carPrint
     * @return
     */
    @Override
    public CarPrint insertCarPrint(CarPrint carPrint){
        try {
            carPrint.setPrintLastTime(this.getDate(0));
            return this.insert(carPrint);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }

    /**
     * 修改打印次数
     * @param carPrint
     * @return
     */
    @Override
    public Integer updateCarPrint(CarPrint carPrint){
        try {
            carPrint.setPrintLastTime(this.getDate(0));
            return this.update(carPrint);
        } catch (Exception e) {
            throw new BusinessException(ExceptionCode.EXCEPTION_CODE0000, e);
        }
    }
}
